/**
 * @author Harsh Shah(Id#6715591)
 * @date 26/07/2014
 * SOEN 6011 - D-1, Eternity-Calculator for Transcendental Functions
 * For all number keys and .,C,+/- keys actions are listened here and output is calculated in this class
 */


package commons;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Numbers implements ActionListener {

	boolean isNegative = false;

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand() == "7") {
			GUI.display.append("7");
		}
		if (e.getActionCommand() == "8") {
			GUI.display.append("8");
		}
		if (e.getActionCommand() == "9") {
			GUI.display.append("9");
		}

		if (e.getActionCommand() == "4") {
			GUI.display.append("4");
		}
		if (e.getActionCommand() == "5") {
			GUI.display.append("5");
		}
		if (e.getActionCommand() == "6") {
			GUI.display.append("6");
		}

		if (e.getActionCommand() == "1") {
			GUI.display.append("1");
		}
		if (e.getActionCommand() == "2") {
			GUI.display.append("2");
		}
		if (e.getActionCommand() == "3") {
			GUI.display.append("3");
		}

		if (e.getActionCommand() == "0") {
			GUI.display.append("0");
		}
		if (e.getActionCommand() == "\u212f") {
			CalculatorHarsh cal=new CalculatorHarsh();
			if(CalculatorHarsh.commonCalc.containsKey(1))
			{
				GUI.display.append(CalculatorHarsh.commonCalc.get(1).toString());
			}else{
				GUI.display.setText(cal.expFunc("1").toString());	
			}
		}
		if (e.getActionCommand() == "\u03C0") {
			Double pi=Math.PI;
			GUI.display.append(pi.toString());
		}
		if (e.getActionCommand() == "\u00B7") {
			String str=GUI.display.getText();
			if(str.equals("")){
				str="0.";
			}else{
				if(str.contains(".")){
					System.out.println(". already inserted");
				}else{
					str=str+".";
				}
				
			}
			GUI.display.setText(str);

		}
		if (e.getActionCommand() == "C") {
			GUI.display.setText("");
			isNegative=false;
		}
		if (e.getActionCommand() == "\u00B1") {
			String neg = "-";
			@SuppressWarnings("unused")
			String pos = "+";
			String str = GUI.display.getText();
			if (isNegative == false) {
				str=neg+str;
				GUI.display.setText(str);
				isNegative = true;
			} else {
				str=str.substring(1);
				GUI.display.setText(str);
				isNegative = false;
			}
		}

	}

}
